package others;

import java.util.Arrays;

/**
 * leet-code(492) 构造矩形
 *
 * @author Ringo
 * @date 2021/10/23 19:57
 */
public class ConstructRectangle {

    public static void main(String[] args) {
        int area = 122122;
        System.out.println(Arrays.toString(constructRectangle(area)));
    }

    public static int[] constructRectangle(int area) {
        int[] ans = {area, 1};
        for (int i = 1; i <= area; ++i) {
            int remain = area % i;
            if (remain == 0 && i >= area / i) {
                int w = area / i;
                if (i - w < ans[0] - ans[1]) {
                    ans[0] = i;
                    ans[1] = w;
                }
            }
        }
        return ans;
    }

}
